package cn.fjgc.dao.impl;

import java.util.ArrayList;
import java.util.List;

import cn.fjgc.entity.Customer;

public class CustomerDatabaseOperate {
	
	BaseDao baseDao;
	public CustomerDatabaseOperate(BaseDao baseDao) {
		this.baseDao = baseDao;
	}
	
	public List<Customer> queryCustomer() throws Exception{
		
		return baseDao.operQuery("select * from customer", new ArrayList<>(), Customer.class);
		
	}
	
	public boolean insertCustomer(Customer customer) {
		List<Object> params = new ArrayList<>();
		params.add(customer.getUserid()); 
		params.add(customer.getUsername()); 
		params.add(customer.getPassword()); 
		params.add(customer.getUsersex()); 
		params.add(customer.getBirthday()); 
		params.add(customer.getEmail()); 
		params.add(customer.getPhoneno()); 
		params.add(customer.getRegdate()); 
		params.add(customer.getLockstate()); 
		params.add(customer.getLastaccess()); 
		params.add(customer.getLogin()); 
		return baseDao.operUpdate("insert into customer values(?,?,?,?,?,?,?,?,?,?,?)",params);
	}
	public boolean updateCustomer(Customer customer) {
		List<Object> params = new ArrayList<>();
		params.add(customer.getUserid());  
		params.add(customer.getPassword()); 
		params.add(customer.getUsersex()); 
		params.add(customer.getBirthday()); 
		params.add(customer.getEmail()); 
		params.add(customer.getPhoneno()); 
		params.add(customer.getRegdate()); 
		params.add(customer.getLockstate()); 
		params.add(customer.getLastaccess()); 
		params.add(customer.getLogin()); 
		params.add(customer.getUsername());
		return baseDao.operUpdate("update customer set userid=?,password=?,usersex=?,birthday=?,email=?,phoneno=?,regdate=?,lockstate=?,lastaccess=?,login=? where username = ?",params);
	}
}
